import request from "@/utils/request";

// 查询物料进货台账列表
export function listMaterialLedger(query) {
  return request({
    url: "/cost/materialLedger/list",
    method: "get",
    params: query,
  });
}

// 查询物料进货台账所有列表
export function listAllMaterialLedger(query) {
  return request({
    url: "/cost/materialLedger/listAll",
    method: "get",
    params: query,
  });
}

// 查询物料进货台账详细
export function getMaterialLedger(id) {
  return request({
    url: "/cost/materialLedger/getInfo/" + id,
    method: "get",
  });
}
// 文件导入（仅上传单个文件）
export function fileImport(file, porjectId, ledgerTypeId) {
  const formData = new FormData();
  const raw = file && file.raw ? file.raw : file;
  if (raw) {
    // 后端现在只需要一个文件
    formData.append("file", raw);
  }
  // 添加项目ID和台账类型ID参数
  if (porjectId) {
    formData.append("porjectId", porjectId);
  }
  if (ledgerTypeId) {
    formData.append("ledgerTypeId", ledgerTypeId);
  }
  return request({
    url: "/cost/materialLedger/importData",
    method: "post",
    data: formData,
    headers: {
      "X-Requested-With": "XMLHttpRequest",
    },
  });
}

// 图片上传（仅上传单个文件）
export function addImg(file) {
  const formData = new FormData();
  const raw = file && file.raw ? file.raw : file;
  if (raw) {
    // 后端现在只需要一个文件
    formData.append("file", raw);
  }
  return request({
    url: "/cost/imageStorage/upDataImage",
    method: "post",
    data: formData,
    headers: {
      "X-Requested-With": "XMLHttpRequest",
    },
  });
}

export function delImg(data) {
  return request({
    url: "/cost/imageStorage/delUpDataImage",
    method: "post",
    data: data,
  });
}

// 新增物料进货台账
export function addMaterialLedger(data) {
  return request({
    url: "/cost/materialLedger/add",
    method: "post",
    data: data,
  });
}

// 修改物料进货台账
export function updateMaterialLedger(data) {
  return request({
    url: "/cost/materialLedger/edit",
    method: "post",
    data: data,
  });
}

// 删除物料进货台账
export function delMaterialLedger(id) {
  return request({
    url: "/cost/materialLedger/remove/" + id,
    method: "get",
  });
}

// 获取项目总含税金额
export function getAmountTotal(ledgerTypeId, projectId) {
  return request({
    url: "/cost/materialLedger/getAmountTotal",
    method: "get",
    params: {
      ledgerTypeId,
      projectId,
    },
  });
}

// 获取项目总含税金额
export function getCountTotal(ledgerTypeId, projectId) {
  return request({
    url: "/cost/materialLedger/getQuantityTotal",
    method: "get",
    params: {
      ledgerTypeId,
      projectId,
    },
  });
}
